﻿using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Rechargeable.Amazon.Localization;
using Rechargeable.Amazon.Web.Menus;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
using Rechargeable.Amazon.Permissions;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.AspNetCore.Mvc;

namespace Rechargeable.Amazon.Web;
[DependsOn(
    typeof(AmazonApplicationContractsModule),
    typeof(AbpAspNetCoreMvcUiThemeSharedModule),
    typeof(AbpAutoMapperModule),
    typeof(Amazon.AmazonApplicationModule)
    )]
public class AmazonWebModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
        {
            options.AddAssemblyResource(typeof(AmazonResource), typeof(AmazonWebModule).Assembly);
        });

        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            mvcBuilder.AddApplicationPartIfNotExists(typeof(AmazonWebModule).Assembly);
        });
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {

        Configure<AbpNavigationOptions>(options =>
        {
            options.MenuContributors.Add(new AmazonMenuContributor());
        });

        Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<AmazonWebModule>();
        });

        context.Services.AddAutoMapperObjectMapper<AmazonWebModule>();
        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddMaps<AmazonWebModule>(validate: true);
        });

        Configure<RazorPagesOptions>(options =>
        {
                //Configure authorization.
        });
        Configure<AbpAspNetCoreMvcOptions>(options =>
        {
            options.ConventionalControllers
                .Create(typeof(Amazon.AmazonApplicationModule).Assembly, opts =>
                {
                    opts.RootPath = AmazonRemoteServiceConsts.RemoteServiceName;
                });
        });

        Configure<DynamicJavaScriptProxyOptions>(options =>
        {
            options.DisableModule(AmazonRemoteServiceConsts.ModuleName);
        });
    }
}
